#include "ethernet.h"

Ethernet eth = Ethernet();

// const char apn[10] = "CMNET";
const char apn[ 10 ]       = "UNINET";
const char URL[ 100 ]      = "mbed.org";
char       http_cmd[ 100 ] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\r\n\r";
int        port            = 80;

int ret = 0;

void setup() {
    SerialUSB.println( "Begin..." );
    eth.Power_On();
    while ( false == eth.Check_If_Power_On() ) {
        SerialUSB.println( "Waitting for module to alvie..." );
        delay( 1000 );
    }

    while ( !eth.init() ) {
        delay( 1000 );
        SerialUSB.println( "Accessing network..." );
    }
    SerialUSB.println( "Initialize done..." );

    eth.join( apn );
    SerialUSB.print( "\n\rIP: " );
    SerialUSB.print( eth.ip_string );

    if ( eth.connect( URL, port, TCP ) ) {
        eth.write( http_cmd );
        while ( MODULE_PORT.available() ) {
            serialDebug.write( MODULE_PORT.read() );
        }
        eth.close( 1 );
    }
    else {
        SerialUSB.println( "Connect Error!" );
    }
}

void loop() {
    /* Debug */
    AT_bypass();
}
